package com.example.wallapp;

import java.util.ArrayList;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

public class CategoryAdapter extends BaseAdapter{
	private ArrayList listData;
	
	private LayoutInflater layoutInflater;
	
	public CategoryAdapter(Context context, ArrayList listData){
		this.listData = listData;
		layoutInflater = LayoutInflater.from(context);
	}
	@Override
	public int getCount(){
		return listData.size();
	}
	@Override
	public Object getItem(int position){
		return listData.get(position);
	}
	@Override
	public long getItemId(int position){
		return position;
	}
	
	public View getView(int position, View convertView, ViewGroup parent){
		ViewHolder holder;
		if(convertView == null){
			convertView = layoutInflater.inflate(R.layout.category_list_row,null);
			holder = new ViewHolder();
			holder.categoryView = (TextView) convertView.findViewById(R.id.category);
			convertView.setTag(holder);
		} else {
			holder = (ViewHolder) convertView.getTag();
		}
		
		holder.categoryView.setText(((CategoryList) listData.get(position)).getCategory());
		
		return convertView;
	}
	
	static class ViewHolder{
		TextView categoryView;
	}
}
